package com.bbs.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.bbs.model.Person;
import com.bbs.service.PersonService;
import com.bbs.web.comm.Constants;

/**
 * @author CharChen
 * @e-mail piggsoft@163.com
 * @since 2013-4-23
 * @version 1.0
 */
@Controller
@Scope("prototype")
public class LoginAction extends AbstractAction{
	
	private String username;
	
	private String password;
	
	private PersonService personService;
	/**
	 * 
	 */
	private static final long serialVersionUID = -4318195693924175176L;
	
	public String execute() {
		Person person = personService.login(username, password);
		if (person == null) {
			setMessage(getText("UI-00005"));
			return INPUT;
		}
		session.put(Constants.SESSION_KEY_USER, person);
		return SUCCESS;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	@Resource
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}
}
